package b1.scenes.fight
{
	import b1.conifg.*;
	import b1.controls.basic.*;
	import b1.net.*;
	
	import com.greensock.*;
	
	import flash.display.Sprite;

	public class Shield extends FightObject
	{
		public var leftFlag:Boolean;
		private var duration:int;
		
		public function Shield(index:int, height:Number, leftFlag:Boolean, duration:int)
		{
			super(leftFlag);
			this.leftFlag = leftFlag;
			this.duration = duration; 
			var ShieldImg:Class = ResourceHelper.getInstance().getClassByName("Obstacle" + index);
			var shieldImg:Sprite = new ShieldImg();
			shieldImg.height = height;
			if (leftFlag)
				shieldImg.scaleX = shieldImg.scaleY;
			else
				shieldImg.scaleX = -shieldImg.scaleY;
			addChild(shieldImg);
			var obstacleConfig:ObstacleConfig = Config.obstacleConfigs[index];
			hitPoints = obstacleConfig.hitPoints;
		}
		
		public override function destroy():void
		{
			super.destroy();
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
		public override function onFightTick():void
		{
			if (duration > 0)
			{
				duration--;
				if (duration == 0)
				{
					TweenLite.to(this, 3, {alpha:0, onComplete:destroy});				
				}
			}
		}
		
	}
}